package com.mew.slots.core.game.fkymr.service;

import com.alibaba.fastjson.JSON;
import com.mew.common.enm.SlotsWinType;
import com.mew.common.entity.game.WinFree;
import com.mew.slots.core.common.game.BaseGameService;
import com.mew.slots.core.common.game.vo.BasePlayMsgs;
import com.mew.slots.core.common.messge.response.SlotsPlayResponseMessage;
import com.mew.slots.core.common.vo.StrategyGameVO;
import com.mew.slots.core.game.fkymr.dto.FkymrInRoom;
import com.mew.slots.core.game.fkymr.dto.FkymrPlayMsgs;
import com.mew.slots.core.game.fkymr.message.FkymrPlayResponseMessage;
import com.mew.slots.core.game.fkymr.roller.FkymrIli;
import com.mew.slots.core.game.fkymr.room.FkymrRoom;
import org.apache.commons.lang3.StringUtils;

/**
 * @author dylin
 */
public class FkymrService extends BaseGameService {
    @Override
    public BasePlayMsgs startGame(StrategyGameVO player) {
        WinFree winFree=player.getWinFree();
        FkymrInRoom vo;
        if (StringUtils.isNotEmpty(winFree.getJson())){
            vo = JSON.parseObject(winFree.getJson(),FkymrInRoom.class);
        }else{
            vo = new FkymrInRoom();
        }
        FkymrRoom room = new FkymrRoom(vo);
        room.init(player.getRollerId(), FkymrIli.getInstance(),vo.getIn(),player.getWinType()==SlotsWinType.Free.code(),player.getInBetNumber(),player.getControlType());
        room.roundPlayIli();
        winFree.setJson(JSON.toJSONString(vo));
        return room.getRes();
    }

    @Override
    public SlotsPlayResponseMessage myResp(WinFree winFree, BasePlayMsgs res) {
        FkymrPlayResponseMessage message = new FkymrPlayResponseMessage();
        FkymrPlayMsgs pmres=(FkymrPlayMsgs) res;
        if(pmres.getBouns()>0){
            message.setBonus(pmres.getBouns());
            winFree.setBounsNumber(5);
        }
        message.setRemoveIcon(pmres.getRemoveIcon());
        message.setFrees(pmres.getFreeNumber());
        return message;
    }

    @Override
    public void myAfterResp(SlotsPlayResponseMessage message,StrategyGameVO player, BasePlayMsgs res) {
        FkymrPlayResponseMessage FkymrPlayResponseMessage = (FkymrPlayResponseMessage)message;
        FkymrPlayResponseMessage.setFreeCount(player.getWinFree().getFreeCount());
    }
}
